<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取变量的类型</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.get-resource-type.html">get_resource_type</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.import-request-variables.html">import_request_variables</a></div>
 <div class="up"><a href="ref.var.html">Variable handling 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.gettype" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">gettype</h1>
    <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">gettype</span> &mdash; <span class="dc-title">获取变量的类型</span></p>

   </div>
   <div class="refsect1 unknown-unknown-unknown-unknown-seealss" id="refsect1-function.gettype-unknown-unknown-unknown-unknown-seealss">
    <h3 class="title">描述</h3>
     <div class="methodsynopsis dc-description">
      <span class="type">string</span> <span class="methodname"><strong>gettype</strong></span>
       ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$var</code></span>
      )</div>

    <p class="para rdfs-comment">
     返回 PHP 变量的类型
     <em><code class="parameter">var</code></em>.
    </p>
    <div class="warning"><strong class="warning">Warning</strong>
     <p class="simpara">
      不要使用 <span class="function"><strong>gettype()</strong></span>
      来测试某种类型，因为其返回的字符串在未来的版本中可能需要改变。此外，由于包含了字符串的比较，它的运行也是较慢的。
      
     </p>
     <p class="simpara">
      使用 <em>is_*</em> 函数代替。
     </p>
    </div>
    <p class="para">
     返回的字符串的可能值为：
     <ul class="itemizedlist">
      <li class="listitem">
       <span class="simpara">“<span class="type"><a href="language.types.boolean.html" class="type boolean">boolean</a></span>”（从 PHP 4 起）</span>
      </li>
      <li class="listitem">
       <span class="simpara">“<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>”</span>
      </li>
      <li class="listitem">
       <span class="simpara">“<span class="type"><a href="language.types.float.html" class="type double">double</a></span>”（由于历史原因，如果是 <span class="type"><a href="language.types.float.html" class="type float">float</a></span> 则返回“double”，而不是“float”）</span>
      </li>
      <li class="listitem">
       <span class="simpara">“<span class="type"><a href="language.types.string.html" class="type string">string</a></span>”</span>
      </li>
      <li class="listitem">
       <span class="simpara">“<span class="type"><a href="language.types.array.html" class="type array">array</a></span>”</span>
      </li>
      <li class="listitem">
       <span class="simpara">“<span class="type"><a href="language.types.object.html" class="type object">object</a></span>”</span>
      </li>
      <li class="listitem">
       <span class="simpara">“<span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>”（从 PHP 4 起）</span>
      </li>
      <li class="listitem">
       <span class="simpara">“<span class="type"><a href="language.types.null.html" class="type NULL">NULL</a></span>”（从 PHP 4 起）</span>
      </li>
      <li class="listitem">
       <span class="simpara">“user function”（只用于 PHP 3，现已停用）</span>
      </li>
      <li class="listitem">
       <span class="simpara">“unknown type”</span>
      </li>
     </ul>
    </p>
    <p class="para">
     对于 PHP 4，你应该使用 <span class="function"><a href="function.function-exists.html" class="function">function_exists()</a></span>
     和 <span class="function"><a href="function.method-exists.html" class="function">method_exists()</a></span>
     取代先前将 <span class="function"><strong>gettype()</strong></span>
     作用于函数的用法。
    </p>
    <p class="para">
     参见
     <span class="function"><a href="function.settype.html" class="function">settype()</a></span>、<span class="function"><a href="function.is-array.html" class="function">is_array()</a></span>、<span class="function"><a href="function.is-bool.html" class="function">is_bool()</a></span>、<span class="function"><a href="function.is-float.html" class="function">is_float()</a></span>、<span class="function"><a href="function.is-integer.html" class="function">is_integer()</a></span>、<span class="function"><a href="function.is-null.html" class="function">is_null()</a></span>、<span class="function"><a href="function.is-numeric.html" class="function">is_numeric()</a></span>、<span class="function"><a href="function.is-object.html" class="function">is_object()</a></span>、<span class="function"><a href="function.is-resource.html" class="function">is_resource()</a></span>、<span class="function"><a href="function.is-scalar.html" class="function">is_scalar()</a></span>
     和 <span class="function"><a href="function.is-string.html" class="function">is_string()</a></span>。
    </p>
   </div>

  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.get-resource-type.html">get_resource_type</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.import-request-variables.html">import_request_variables</a></div>
 <div class="up"><a href="ref.var.html">Variable handling 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
